

public class Offer57 {
    public int[] twoSum(int[] nums, int target) {
        int left =0;
        int right = nums.length-1;
        int currentNum;
        while (left<=right){
            currentNum = nums[left]+nums[right];
            if (currentNum<target){
                left++;
            }else if (currentNum>target){
                right--;
            }else {
                return new int[]{nums[left],nums[right]};
            }
        }
        return new int[0];
    }
}
